<template>
  <div class="dashboard-editor-container">
    <!-- <github-corner class="github-corner" /> -->

    <panel-group @handleSetLineChartData="handleSetLineChartData" />

    <!-- <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="lineChartData" />
    </el-row> -->

    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :lg="15">
        <div class="chart-wrapper">
          <!-- <raddar-chart /> -->
          <div class="top">
            <div class="line"></div>
            <div class="title">今日消费详情</div>
          </div>

          <el-table
            :data="xtableData"
            :header-cell-style="{background:'#FAFAFA',color:'#666666'}"
            style="width: 100%">
            <el-table-column align="center"
              label="用户">
              <template slot-scope="scope">
                <span>{{ scope.row.username }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center"
              label="消费餐桌">
              <template slot-scope="scope">
                <span>{{ scope.row.tablename ? scope.row.tablename : '无' }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center"
              label="消费商品" width="300">
              <template slot-scope="scope">
                <span>{{ scope.row.title }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center"
              label="消费时间">
              <template slot-scope="scope">
                <span>{{ scope.row.updated_at }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center"
              label="消费金额">
              <template slot-scope="scope">
                <span>{{ (scope.row.order_total/100).toFixed(2) }}</span>
              </template>
            </el-table-column>
          </el-table>
          <pagination :total="xtotal" :page.sync="xlistQuery.page" :layout="'prev, pager, next'" :limit.sync="xlistQuery.limit" @pagination="getXList" />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="9">
        <div class="chart-wrapper">
          <!-- <pie-chart /> -->
          <div class="top">
            <div class="line"></div>
            <div class="title">今日充值详情</div>
          </div>
          <el-table
            :data="ctableData"
            :header-cell-style="{background:'#FAFAFA',color:'#666666'}"
            style="width: 100%">
            <el-table-column align="center"
              label="用户">
              <template slot-scope="scope">
                <span>{{ scope.row.username }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center"
              label="充值时间">
              <template slot-scope="scope">
                <span>{{ scope.row.updated_at }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center"
              label="充值金额">
              <template slot-scope="scope">
                <span>{{ (scope.row.number/100).toFixed(2) }}</span>
              </template>
            </el-table-column>
          </el-table>
          <pagination :total="ctotal" :page.sync="clistQuery.page" :layout="'prev, pager, next'" :limit.sync="clistQuery.limit" @pagination="getCList" />
        </div>
      </el-col>
      <!-- <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <bar-chart />
        </div>
      </el-col> -->
    </el-row>

   <!-- <el-row :gutter="8">
      <el-col :xs="{span: 24}" :sm="{span: 24}" :md="{span: 24}" :lg="{span: 12}" :xl="{span: 12}" style="padding-right:8px;margin-bottom:30px;">
        <transaction-table />
      </el-col>
      <el-col :xs="{span: 24}" :sm="{span: 12}" :md="{span: 12}" :lg="{span: 6}" :xl="{span: 6}" style="margin-bottom:30px;">
        <todo-list />
      </el-col>
      <el-col :xs="{span: 24}" :sm="{span: 12}" :md="{span: 12}" :lg="{span: 6}" :xl="{span: 6}" style="margin-bottom:30px;">
        <box-card />
      </el-col>
    </el-row> -->
  </div>
</template>

<script>
import GithubCorner from '@/components/GithubCorner'
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import RaddarChart from './components/RaddarChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'
import TransactionTable from './components/TransactionTable'
import TodoList from './components/TodoList'
import BoxCard from './components/BoxCard'

import Pagination from '@/components/Pagination'
import { getHomeInfo, getCudetail, getDrawlist } from '@/api/home'

const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'DashboardAdmin',
  components: {
    GithubCorner,
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,
    TransactionTable,
    TodoList,
    BoxCard,
    Pagination
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
      xtableData: [],
      ctableData: [],
      xtotal: 0,
      ctotal: 0,
      xlistQuery: {
        page: 1,
        limit: 10
      },
      clistQuery: {
        page: 1,
        limit: 10
      }
    }
  },
  created() {
    this.getXList()
    this.getCList()
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },
    getXList() {
      getCudetail(this.xlistQuery).then(res=>{
        this.xtableData = res.data.list
        this.xtotal = res.data.total
      })
    },
    getCList() {
      getDrawlist(this.clistQuery).then(res=>{
        this.ctableData = res.data.list
        this.ctotal = res.data.total
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px 32px 32px 16px;
  background-color: #F8F7F7;
  position: relative;
  min-height: calc(100vh - 56px);

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 23px 20px;
    margin-bottom: 20px;
    border: 1px solid #F1F0F0;
    border-radius: 3px;
    .top{
      display: flex;
      align-items: center;
      padding-bottom: 23px;
      .line{
        width: 3px;
        height: 18px;
        background: #E6184E;
        border-radius: 8px;
        margin-right: 7px;
      }
      .title{
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        color: #333333;
      }
    }
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
